package vista;

import org.joda.time.LocalTime;
import org.joda.time.format.DateTimeFormat;
import org.uqbar.arena.bindings.Transformer;
import org.uqbar.commons.model.UserException;

public class HoraToStringAdapter implements Transformer<LocalTime, String> {

	@Override
	public LocalTime viewToModel(String valueFromView) {
		try{
			return LocalTime.parse(valueFromView, DateTimeFormat.forPattern("HH:mm"));
		}catch(IllegalArgumentException e){
			throw new UserException("Ingrese una hora valida en formato hh:mm");
		}
	}

	@Override
	public String modelToView(LocalTime valueFromModel) {
		return valueFromModel.toString("HH:mm");
	}

	@Override
	public Class<LocalTime> getModelType() {
		return LocalTime.class;
	}

	@Override
	public Class<String> getViewType() {
		return String.class;
	}



}
